package com.deuwise.config.oauth2;

import com.deuwise.common.utils.SpringContextHolder;
import com.deuwise.system.service.ShiroService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Set;

/**
 * Copyright
 *
 * @author chenwenchao
 * @date 2019/2/21
 * Description:
 */
public class UserPermissionUtils {

    public  static Set<String> getPermissionStr(){

        ShiroService shiroService= SpringContextHolder.getBean(ShiroService.class);
        String authorization = (String) SecurityUtils.getSubject().getPrincipal();
        if(!StringUtils.isEmpty(authorization)) {
            String userId = JWTUtil.getUserId(authorization);
            //根据accessToken，查询用户信息
            //用户权限列表
            Set<String> permsSet = shiroService.getUserPermissions(userId);
            return  permsSet;
        }
        return  null;
    }
}
